package com.situ.personal.controller;

import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.situ.personal.dao.DepartmentDao;
import com.situ.personal.entity.Department;
import com.situ.personal.util.JSONUtil;
import com.situ.personal.vo.DepartmentUserCountVO;
@WebServlet("/departmnet")
public class DepartmentServlet extends HttpServlet {
	private DepartmentDao departmentDao = new DepartmentDao();

	protected void service(HttpServletRequest req, HttpServletResponse resp) {
    	 String method = req.getParameter("method");
    	 switch (method) {
		case "selectAllByJson":
			selectAllByJson(req, resp);
			break;
		case "departmentUserCount":
			departmentUserCount(req, resp);
            break;
		default:
			break;
		}
		
	}

	private void departmentUserCount(HttpServletRequest req, HttpServletResponse resp) {
		List<DepartmentUserCountVO> list= departmentDao.departmentUserCount();
		JSONUtil.array2Json(list, resp);
	}

	private void selectAllByJson(HttpServletRequest req, HttpServletResponse resp) {
		System.out.println("DepartmentServlet.selectAllByJson()");
		List<Department> list = departmentDao.selectAll();
		
		JSONUtil.array2Json(list, resp);
		
	}
}
